﻿using System;
using System.Runtime.Serialization;

using SBPweb.PROvibe.Shared.Contracts.Content;

namespace SBPweb.PROvibe.Shared.Contracts.Content
{

    public struct TypeDescriptor// : ITypeDescriptor
    {

        #region Private fields

        private string xapPath;
        private string asmPath;
        private string fqTypeName;

        #endregion

        #region Constructor logic

        public TypeDescriptor(string fullName)
        {
            Uri uri = new Uri(fullName);
            this.xapPath = uri.Host;
            this.asmPath = uri.LocalPath.Substring(1);
            int pos = uri.Query.IndexOf("class=");
            if (pos >= 0)
            {
                this.fqTypeName = uri.Query.Substring(pos + 6);
            }
            else
            {
                this.fqTypeName = null;
            }
        }

        public TypeDescriptor(string xapPath, string asmPath, string typeName)
        {
            this.xapPath = xapPath;
            this.asmPath = asmPath;
            this.fqTypeName = typeName;
        }

        #endregion

        #region Property accessors

        public string XapPath
        {
            get
            {
                return xapPath;
            }
            set
            {
                xapPath = value;
            }
        }

        public string AssemblyPath
        {
            get
            {
                return asmPath;
            }
            set
            {
                asmPath = value;
            }
        }

        public string FullyQualifiedTypeName
        {
            get
            {
                return fqTypeName;
            }
            set
            {
                fqTypeName = value;
            }
        }

        #endregion

        #region Methods
        
        public override string ToString()
        {
            return string.Format("xap://{0}/{1}?class={2}", XapPath, AssemblyPath, FullyQualifiedTypeName);
        }

        #endregion

    }

}
